package com.iocup.keybastion.spring.starter.config;


import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Description: 单点
 * @Author: xyjxust
 * @Date: 2022/3/23 14:36
 */
public class EnabledSsoServerCondition extends SpringBootCondition {
    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String[] enablers = context.getBeanFactory()
                .getBeanNamesForAnnotation(EnabledSsoServer.class);
        ConditionMessage.Builder message = ConditionMessage
                .forCondition("@EnabledSsoServer Condition");
        if (enablers != null && enablers.length > 0) {
            return ConditionOutcome.match(message
                    .found("@EnabledSsoServer annotation on Application")
                    .items(enablers));
        }

        return ConditionOutcome.noMatch(message.didNotFind(
                        "@EnabledSsoServer annotation " + "on Application")
                .atAll());
    }
}
